package conexãoGrid;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 *
 * @author kaio
 */
public class Comandos {
    private StringBuffer Retorno;
    private StringBuffer Erros;
    public void executaComando(String comando){
        String retorno;
        this.Retorno = new StringBuffer();
        this.Erros = new StringBuffer();

        try{
            Process processo = Runtime.getRuntime().exec(comando);
            InputStream StreamEntrada = processo.getInputStream();
            InputStream StreamErro = processo.getErrorStream();
            BufferedReader saidaProcesso;

            saidaProcesso = new BufferedReader(new InputStreamReader(StreamEntrada));
            while((retorno = saidaProcesso.readLine())!=null){
                this.Retorno.append(retorno+"\r\n");
            }
            saidaProcesso = new BufferedReader(new InputStreamReader(StreamErro));
            while((retorno = saidaProcesso.readLine())!=null){
                this.Erros.append(retorno+"\r\n");
            }
            processo.waitFor();
            saidaProcesso.close();
            StreamErro.close();
            StreamEntrada.close();
            processo.getOutputStream().close();

        }catch(Exception ex){
            
        }

        
    }
    public String pegaRetorno(){
        if (this.Retorno.length()>0){
            return this.Retorno.toString();
        }else{
            return null;
        }

    }
    public String pegaErro(){
        if (this.Erros.length()>0){
            return this.Erros.toString();
        }else{
            return null;
        }

    }
   
}